package smokesignals.data;

import com.google.common.base.Preconditions;
import com.googlecode.recycled.data.DataStore;
import com.googlecode.recycled.data.WithId;

/**
 * @author Henryk Konsek
 */
public class BaseDao<I, W extends WithId<I>> implements Dao<I, W> {

    protected Class<W> type;

    protected DataStore<I> dataStore;

    public BaseDao(Class<W> type, DataStore<I> dataStore) {
        Preconditions.checkNotNull(type);
        Preconditions.checkNotNull(dataStore);
        this.type = type;
        this.dataStore = dataStore;
    }

    @Override
    public void store(W withId) {
        dataStore.store(withId);
    }

    @Override
    public void delete(W value) {
        dataStore.delete(value);
    }

    @Override
    public W load(I id) {
        return dataStore.load(type, id);
    }

    @Override
    public <Q> Iterable<W> query(Q query, Object... parameters) {
        return dataStore.query(query, parameters);
    }

}
